using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;

using ClassBuilderWizard.Interfaces;

namespace ClassBuilderWizard
{
    public class Plugin : IPlugin, IDisposable
    {
        private IPlugin _InternalPlugin;
        private Type _PluginClass;
        private string _Path;

        public Plugin(string pluginFilePath, Type pluginClass)
        {
            this._Path = pluginFilePath;
            this._PluginClass = pluginClass;

            this._InternalPlugin = Activator.CreateInstance(this._PluginClass) as IPlugin;
        }

        #region IPlugin Members

        public string Name
        {
            get
            {
                if (this._InternalPlugin != null)
                    return this._InternalPlugin.Name;
                else
                    return "Not a valid plugin";
            }
        }

        public string Version
        {
            get
            {
                if (this._InternalPlugin != null)
                    return this._InternalPlugin.Version;
                else
                    return string.Empty;
            }
        }

        public string Author
        {
            get
            {
                if (this._InternalPlugin != null)
                    return this._InternalPlugin.Author;
                else
                    return string.Empty;
            }
        }

        public ProjectType[] SupportedProjectTypes
        {
            get
            {
                if (this._InternalPlugin != null)
                    return this._InternalPlugin.SupportedProjectTypes;
                else
                    return new ProjectType[] { };
            }
        }

        public System.Drawing.Bitmap Icon
        {
            get
            {
                if (this._InternalPlugin != null)
                    return this._InternalPlugin.Icon;
                else
                    return new System.Drawing.Bitmap(0, 0);
            }
        }

        public PluginType PluginType
        {
            get
            {
                if (this._InternalPlugin != null)
                    return this._InternalPlugin.PluginType;
                else
                    return PluginType.Unknown;
            }
        }

        #endregion

        public IPlugin PluginInterface
        {
            get { return this._InternalPlugin; }
        }

        #region IDisposable Members

        public void Dispose()
        {
            this._InternalPlugin.Dispose();
            this._PluginClass = null;
            this._Path = null;
        }

        #endregion
    }
}
